package com.link.base.base.member.controller;

import com.link.base.base.member.model.GiftCardPage;
import com.link.base.base.member.service.GiftCardPageService;
import com.link.base.wechat.wxcard.model.Page;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 礼品卡货架对象
 *
 * @author 路江
 * @date 2019/03/02 10:25
 */
@Controller
@RequestMapping("/link/giftCardPage")
public class GiftCardPageController extends BasicController<GiftCardPage> {
 
    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private GiftCardPageService giftCardPageService;

    @Override
    public BasicService<GiftCardPage> getBasicService() throws Exception {
        return giftCardPageService;
    }

    /**
     * 创建-礼品卡货架接口
     *
     * @author lujiang
     * @date 2019-03-01
     * @param page 礼品卡货架接口对象
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/createGiftCardPage")
    @ResponseBody
    public Map<String, Object> createGiftCardPage(@RequestBody Page page) throws Exception {
        Map<String, Object> result = new HashMap<>(16) ;
        try {
            result = giftCardPageService.createGiftCardPage(page,"NEW");
            result.put("success",true);
        } catch (Exception e) {
            result.put("success",false);
            result.put("msg",e.getMessage());
        }
        return result;
    }

    /**
     * 查询-礼品卡货架接口
     *
     * @author lujiang
     * @date 2019-03-01
     * @param page 礼品卡货架接口对象
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryGiftCardPageById")
    @ResponseBody
    public Map<String, Object> queryGiftCardPageById(@RequestBody GiftCardPage page) throws Exception {
        Map<String, Object> result = new HashMap<>(16) ;
        try {
            result = giftCardPageService.queryGiftCardPageById(page);
            result.put("success",true);
        } catch (Exception e) {
            result.put("success",false);
            result.put("msg",e.getMessage());
        }
        return result;
    }

    /**
     * 修改-礼品卡货架接口
     *
     * @author lujiang
     * @date 2019-03-05
     * @param page 礼品卡货架接口对象
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateGiftCardPage")
    @ResponseBody
    public Map<String, Object> updateGiftCardPage(@RequestBody Page page) throws Exception {
        Map<String, Object> result = new HashMap<>(16) ;
        try {
            result = giftCardPageService.createGiftCardPage(page,"UPDATE");
            result.put("success",true);
        } catch (Exception e) {
            result.put("success",false);
            result.put("msg",e.getMessage());
        }
        return result;
    }
}
